﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using HKEA.CMS.Core.BLL;
using HKEA.CMS.Core.Models;
using HKEA.CMS.Core.Utility;
using iMaker.Library;
using HKEA.CMS.Core.BLL.Tbl;

namespace WebApplication
{
    public partial class CustomerLog : BasePage
    {
        protected static string CustomerUID = string.Empty;
        private int defaultCurPage = 1;
        private string defaultPropertyName = "h.CreationDate";
        private string defaultOrderBy = "desc";

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                CustomerUID = Request.QueryString[Constant.UrlParamName.CustomerUID];
                string page = Request.QueryString[Constant.UrlParamName.CurrentPage];
                string propertyname = Request.QueryString[Constant.UrlParamName.PropertyName];
                string orderby = Request.QueryString[Constant.UrlParamName.OrderBy];
                string startDate=Request.QueryString[Constant.UrlParamName.StartDate];
                string endDate = Request.QueryString[Constant.UrlParamName.EndDate];

                if (string.IsNullOrEmpty(CustomerUID))
                {
                    usermeg.Visible = false;
                }
                else
                {
                    if (!string.IsNullOrEmpty(propertyname) && !string.IsNullOrEmpty(orderby))
                    {
                        defaultPropertyName = propertyname; defaultOrderBy = orderby;
                    }

                    if (!string.IsNullOrEmpty(page))
                    {
                        defaultCurPage = int.Parse(page);
                    }

                    BindDataSource(defaultCurPage, defaultPropertyName, defaultOrderBy,startDate,endDate);
                }
            }
        }

        /// <summary>
        /// 根据参数（当前页和排序 字段和升降序） 绑定 列表
        /// </summary>
        /// <param name="curPage"></param>
        /// <param name="strPropertyName"></param>
        /// <param name="strOrderBy"></param>
        private void BindDataSource(int curPage, string strPropertyName, string strOrderBy,string startDate,string endDate)
        {
            tblHistoryBLL bll = new tblHistoryBLL();
            tblHistory entParam = new tblHistory();

            int custUID = 0;
            int.TryParse(CustomerUID, out custUID);
            //entParam.CustomerUID = custUID;

            PagerCollection pager = new PagerCollection();
            pager.PageSize = Constant.PerPageRecordCount.common;
            pager.CurPage = curPage;

            paginator1.pager = pager;
            paginator2.pager = pager;

            IQueryable list = bll.GetListByENT(entParam, pager, strPropertyName, strOrderBy, startDate, endDate);

            if (list != null)
            {
                Repeater1.DataSource = list;
                Repeater1.DataBind();
            }        
        }
    }
}